
package javanlp;

import java.io.*;
import opennlp.tools.cmdline.*;
import opennlp.tools.cmdline.postag.*;
import opennlp.tools.postag.*;
import opennlp.tools.tokenize.WhitespaceTokenizer;
import opennlp.tools.util.*;

public class tagPOS{
	public static void main(String[] args) throws IOException {
            String fld = "C:/Users/lenovolap/Dropbox/java/NLP.models/";
        String trainedModel = fld+"en-pos-maxent.zip";
	POSModel model = new POSModelLoader().load(new File(trainedModel));
	PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
	POSTaggerME tagger = new POSTaggerME(model);
 	String ip = "This is Mike.OpenNLP is one of the coolest tools.";
	ObjectStream<String> lStream = 
                new PlainTextByLineStream(new StringReader(ip));
 	perfMon.start();
	String line;
	while ((line = lStream.read()) != null) {
             String[] wsTokenizerLine = WhitespaceTokenizer.INSTANCE
		.tokenize(line);
             String[] tags = tagger.tag(wsTokenizerLine);
             POSSample sample = new POSSample(wsTokenizerLine, tags);
	     System.out.println(sample.toString());
             perfMon.incrementCounter();
	     }
	perfMon.stopAndPrintFinalResult();
	}
}